﻿using ReactiveUI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace PlatingLineUI
{
    /// <summary>
    /// CenterBorder.xaml 的交互逻辑
    /// </summary>
    /// <summary>
    /// 
    /// </summary>
    public class CenterBorder : ContentControl
    {


        

        /// <summary>
        ///宽度偏移
        /// </summary>
        public static readonly DependencyProperty TypeFaceVisiableProperty = DependencyProperty.Register(nameof(TypeFacsVisiable), typeof(Visibility), typeof(CenterBorder));

        /// <summary>
        ///宽度偏移
        /// </summary>
        public Visibility TypeFacsVisiable
        {
            get { return (Visibility)GetValue(TypeFaceVisiableProperty); }
            set { SetValue(TypeFaceVisiableProperty, value); }
        }

        /// <summary>
        ///宽度偏移
        /// </summary>
        public static readonly DependencyProperty WidthOffsetProperty = DependencyProperty.Register(nameof(WidthOffset), typeof(double), typeof(CenterBorder));

        /// <summary>
        ///宽度偏移
        /// </summary>
        public double WidthOffset
        {
            get { return (double)GetValue(WidthOffsetProperty); }
            set { SetValue(WidthOffsetProperty, value); }
        }

        /// <summary>
        ///图标大小
        /// </summary>
        public static readonly DependencyProperty IconFontSizeProperty = DependencyProperty.Register(nameof(IconFontSize), typeof(double), typeof(CenterBorder));

        /// <summary>
        ///图标大小
        /// </summary>
        public double IconFontSize
        {
            get { return (double)GetValue(IconFontSizeProperty); }
            set { SetValue(IconFontSizeProperty, value); }
        }


        /// <summary>
        ///高度偏移
        /// </summary>
        public static readonly DependencyProperty HeightOffsetProperty = DependencyProperty.Register(nameof(HeightOffset), typeof(double), typeof(CenterBorder));

        /// <summary>
        ///高度偏移
        /// </summary>
        public double HeightOffset
        {
            get { return (double)GetValue(HeightOffsetProperty); }
            set { SetValue(HeightOffsetProperty, value); }
        }

        /// <summary>
        ///文本
        /// </summary>
        public static readonly DependencyProperty TextProperty = DependencyProperty.Register(nameof(Text), typeof(string), typeof(CenterBorder));

        /// <summary>
        ///文本
        /// </summary>
        public string Text
        {
            get { return (string)GetValue(TextProperty); }
            set { SetValue(TextProperty, value); }
        }

        /// <summary>
        ///字体大小
        /// </summary>
        public static readonly DependencyProperty FontSizeProperty = DependencyProperty.Register(nameof(FontSize), typeof(double), typeof(CenterBorder));

        /// <summary>
        ///字体大小
        /// </summary>
        public double FontSize
        {
            get { return (double)GetValue(FontSizeProperty); }
            set { SetValue(FontSizeProperty, value); }
        }

        /// <summary>
        ///字体偏移
        /// </summary>
        public static readonly DependencyProperty TypeFaceMagginProperty = DependencyProperty.Register(nameof(TypeFaceMaggin), typeof(Thickness), typeof(CenterBorder));

        /// <summary>
        ///字体偏移
        /// </summary>
        public Thickness TypeFaceMaggin
        {
            get { return (Thickness)GetValue(TypeFaceMagginProperty); }
            set { SetValue(TypeFaceMagginProperty, value); }
        }

        /// <summary>
        ///是否启用X偏移
        /// </summary>
        public static readonly DependencyProperty IsUseXOffsetProperty = DependencyProperty.Register(nameof(IsUseXOffset), typeof(bool), typeof(CenterBorder));

        /// <summary>
        ///是否启用X偏移
        /// </summary>
        public bool IsUseXOffset
        {
            get { return (bool)GetValue(IsUseXOffsetProperty); }
            set { SetValue(IsUseXOffsetProperty, value); }
        }

        /// <summary>
        ///是否启用Y偏移
        /// </summary>
        public static readonly DependencyProperty IsUseYOffsetProperty = DependencyProperty.Register(nameof(IsUseYOffset), typeof(bool), typeof(CenterBorder));

        /// <summary>
        ///是否启用Y偏移
        /// </summary>
        public bool IsUseYOffset
        {
            get { return (bool)GetValue(IsUseYOffsetProperty); }
            set { SetValue(IsUseYOffsetProperty, value); }
        }



        public CenterBorder()
        {
            this.WhenAnyValue(x => x.Width).Subscribe(x => { WidthChange(); });
            this.WhenAnyValue(x => x.Height).Subscribe(x => { HeightChange(); });
            this.WhenAnyValue(x => x.IsUseXOffset).Subscribe(x=>{WidthChange();});
            this.WhenAnyValue(x => x.IsUseYOffset).Subscribe(x=>{HeightChange();});
        }

        static CenterBorder()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(CenterBorder), new FrameworkPropertyMetadata(typeof(CenterBorder)));
        }

        public void WidthChange()
        {
            if (!this.IsUseXOffset)
            {
                return;
            }
            WidthOffset = -Width / 2;
        }

        public void HeightChange()
        {
            if (!this.IsUseYOffset)
            {
                return;
            }
            HeightOffset = -Height / 2;
        }

        public void WidthChange(double value)
        {
           
        }

        public void HeightChange(double value)
        {
           
        }
    }
}
